package cn.acac.yygh.hosp.controller.user;

import cn.acac.yygh.hosp.service.HospitalService;
import cn.acac.yygh.model.hosp.Hospital;
import cn.acac.yygh.result.R;
import cn.acac.yygh.vo.hosp.HospitalQueryVo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api("用户医院的相关操作")
@RequestMapping("/user/hosp/hospital")
public class UserHospitalController {

    @Autowired
    private HospitalService hospitalService;

    /**
     * 根据医院的编号查询医院的信息
     * @param hoscode
     * @return
     */
    @GetMapping("/findHospByHoscode/{hoscode}")
    public R findHospByHoscode(@PathVariable("hoscode") String hoscode){
        Hospital hospital = hospitalService.findHospByHoscode(hoscode);
        return R.ok().setData("hospital",hospital);
    }

    /**
     * 根据查询条件查询满足条件的医院信息
     * @param hospitalQueryVo
     * @return
     */
    @GetMapping("/list")
    public R selectList(HospitalQueryVo hospitalQueryVo){
        Page<Hospital> hospitalPage = hospitalService.findHospitalPage(1, 1000, hospitalQueryVo);
        return R.ok().setData("list",hospitalPage.getContent());
    }


    /**
     * 根据医院名称进行模糊查询
     * @param name
     * @return
     */
    @GetMapping("/{name}")
    public R findHospByName(@PathVariable("name")String name){
        List<Hospital> hospitalList = hospitalService.findHospByName(name);
        return R.ok().setData("list",hospitalList);
    }
}
